/*
 * Copyright (C) 2014 Realtek Semiconductor Corp.
 * All Rights Reserved.
 *
 * This program is the proprietary software of Realtek Semiconductor
 * Corporation and/or its licensors, and only be used, duplicated,
 * modified or distributed under the authorized license from Realtek.
 *
 * ANY USE OF THE SOFTWARE OTHER THAN AS AUTHORIZED UNDER
 * THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
 *
 * Purpose : Definition of ME handler: ME (65427) get priority to queue setting
 *
 * Feature : The file includes the following modules and sub-modules
 *           (1) ME handler: me (65427)
 */

#include "app_basic.h"
#include "feature_mgmt.h"

#define MIB_TABLE_ME65427_ATTR_NUM              (3)
#define MIB_TABLE_ME65427_ENTITYID_INDEX        ((MIB_ATTR_INDEX)1)
#define MIB_TABLE_ME65427_NO1_ATTR              ((MIB_ATTR_INDEX)2)
#define MIB_TABLE_ME65427_NO2_ATTR              ((MIB_ATTR_INDEX)3)


/* Table me 65427 stucture */
typedef struct
{
    UINT16 EntityID;
    UINT16 no1;
    UINT8  no2[25];
} __attribute__((aligned)) MIB_TABLE_ME65427_T;


MIB_TABLE_INFO_T gMibMe65427TableInfo;
MIB_ATTR_INFO_T gMibMe65427AttrInfo[MIB_TABLE_ME65427_ATTR_NUM];
MIB_TABLE_ME65427_T gMibMe65427DefRow;
MIB_TABLE_OPER_T gMibMe65427Oper;

GOS_ERROR_CODE omci_mib_me_65427_oper_reset(UINT32 args_num, ...)
{
    MIB_TABLE_ME65427_T me65427;

    /*ME-65408*/  
    memset(&me65427, 0x0, sizeof(me65427));
    MIB_Default(MIB_TABLE_ME65427_INDEX, &me65427, sizeof(MIB_TABLE_ME65427_T));
    me65427.EntityID = 0xFF80;
    me65427.no1 = 0xFE00;
    me65427.no2[0] = 0x52;
    me65427.no2[1] = 0x53;
    me65427.no2[2] = 0x51;
    me65427.no2[3] = 0x51;
    me65427.no2[4] = 0x51;
    me65427.no2[5] = 0x53;
    me65427.no2[6] = 0x51;
    OMCI_LOG(OMCI_LOG_LEVEL_INFO, "Resetting MIB: me65427:%x ", me65427.EntityID);
    GOS_ASSERT(GOS_OK == MIB_Set(MIB_TABLE_ME65427_INDEX, &me65427, sizeof(MIB_TABLE_ME65427_T)));
    OMCI_MeOperCfg(MIB_TABLE_ME65427_INDEX, NULL, &me65427, MIB_ADD,
                   omci_GetOltAccAttrSet(MIB_TABLE_ME65427_INDEX, OMCI_ME_ATTR_ACCESS_SBC), OMCI_MSG_BASELINE_PRI_LOW);

    /*ME-65414*/   
    memset(&me65427, 0x0, sizeof(me65427));
    MIB_Default(MIB_TABLE_ME65427_INDEX, &me65427, sizeof(MIB_TABLE_ME65427_T));
    me65427.EntityID = 0xFF86;
    me65427.no1 = 0xFFF0;
    me65427.no2[0] = 0x51;
    me65427.no2[1] = 0x51;
    me65427.no2[2] = 0x51;
    me65427.no2[3] = 0x51;
    me65427.no2[4] = 0x51;
    me65427.no2[5] = 0x51;
    me65427.no2[6] = 0x51;
    me65427.no2[7] = 0x51;
    me65427.no2[8] = 0x51;
    me65427.no2[9] = 0x51;
    me65427.no2[10] = 0x51;
    me65427.no2[11] = 0x51;
    OMCI_LOG(OMCI_LOG_LEVEL_INFO, "Resetting MIB: me65427:%x ", me65427.EntityID);
    GOS_ASSERT(GOS_OK == MIB_Set(MIB_TABLE_ME65427_INDEX, &me65427, sizeof(MIB_TABLE_ME65427_T)));
    OMCI_MeOperCfg(MIB_TABLE_ME65427_INDEX, NULL, &me65427, MIB_ADD,
                   omci_GetOltAccAttrSet(MIB_TABLE_ME65427_INDEX, OMCI_ME_ATTR_ACCESS_SBC), OMCI_MSG_BASELINE_PRI_LOW);

    /*ME-65415*/     
    memset(&me65427, 0x0, sizeof(me65427));
    MIB_Default(MIB_TABLE_ME65427_INDEX, &me65427, sizeof(MIB_TABLE_ME65427_T));
    me65427.EntityID = 0xFF87;
    me65427.no1 = 0xC000;
    me65427.no2[0] = 0x53;
    me65427.no2[1] = 0x71;
    OMCI_LOG(OMCI_LOG_LEVEL_INFO, "Resetting MIB: me65427:%x ", me65427.EntityID);
    GOS_ASSERT(GOS_OK == MIB_Set(MIB_TABLE_ME65427_INDEX, &me65427, sizeof(MIB_TABLE_ME65427_T)));
    OMCI_MeOperCfg(MIB_TABLE_ME65427_INDEX, NULL, &me65427, MIB_ADD,
                   omci_GetOltAccAttrSet(MIB_TABLE_ME65427_INDEX, OMCI_ME_ATTR_ACCESS_SBC), OMCI_MSG_BASELINE_PRI_LOW);

    /*ME-65417*/   
    memset(&me65427, 0x0, sizeof(me65427));
    MIB_Default(MIB_TABLE_ME65427_INDEX, &me65427, sizeof(MIB_TABLE_ME65427_T));
    me65427.EntityID = 0xFF89;
    me65427.no1 = 0xFF00;
    me65427.no2[0] = 0x53;
    me65427.no2[1] = 0x53;
    me65427.no2[2] = 0x53;
    me65427.no2[3] = 0x53;
    me65427.no2[4] = 0x53;
    me65427.no2[5] = 0x53;
    me65427.no2[6] = 0x53;
    me65427.no2[7] = 0x53;
    OMCI_LOG(OMCI_LOG_LEVEL_INFO, "Resetting MIB: me65427:%x ", me65427.EntityID);
    GOS_ASSERT(GOS_OK == MIB_Set(MIB_TABLE_ME65427_INDEX, &me65427, sizeof(MIB_TABLE_ME65427_T)));
    OMCI_MeOperCfg(MIB_TABLE_ME65427_INDEX, NULL, &me65427, MIB_ADD,
                   omci_GetOltAccAttrSet(MIB_TABLE_ME65427_INDEX, OMCI_ME_ATTR_ACCESS_SBC), OMCI_MSG_BASELINE_PRI_LOW);


    /*ME-377*/                   
    memset(&me65427, 0x0, sizeof(me65427));
    MIB_Default(MIB_TABLE_ME65427_INDEX, &me65427, sizeof(MIB_TABLE_ME65427_T));
    me65427.EntityID = 0x0179;
    me65427.no1 = 0xFFFF;
    me65427.no2[0] = 0x51;
    me65427.no2[1] = 0x51;
    me65427.no2[2] = 0x51;
    me65427.no2[3] = 0x51;
    me65427.no2[4] = 0x51;
    me65427.no2[5] = 0x51;
    me65427.no2[6] = 0x51;
    me65427.no2[7] = 0x51;
    me65427.no2[8] = 0x51;
    me65427.no2[9] = 0x51;
    me65427.no2[10] = 0x51;
    me65427.no2[11] = 0x51;
    me65427.no2[12] = 0x51;
    me65427.no2[13] = 0x51;
    me65427.no2[14] = 0x51;
    me65427.no2[15] = 0x51;
    OMCI_LOG(OMCI_LOG_LEVEL_INFO, "Resetting MIB: me65427:%x ", me65427.EntityID);
    GOS_ASSERT(GOS_OK == MIB_Set(MIB_TABLE_ME65427_INDEX, &me65427, sizeof(MIB_TABLE_ME65427_T)));
    OMCI_MeOperCfg(MIB_TABLE_ME65427_INDEX, NULL, &me65427, MIB_ADD,
                   omci_GetOltAccAttrSet(MIB_TABLE_ME65427_INDEX, OMCI_ME_ATTR_ACCESS_SBC), OMCI_MSG_BASELINE_PRI_LOW);

    /*ME-65431*/     
    memset(&me65427, 0x0, sizeof(me65427));
    MIB_Default(MIB_TABLE_ME65427_INDEX, &me65427, sizeof(MIB_TABLE_ME65427_T));
    me65427.EntityID = 0xFF97;
    me65427.no1 = 0x8000;
    me65427.no2[0] = 0x53;
    OMCI_LOG(OMCI_LOG_LEVEL_INFO, "Resetting MIB: me65427:%x ", me65427.EntityID);
    GOS_ASSERT(GOS_OK == MIB_Set(MIB_TABLE_ME65427_INDEX, &me65427, sizeof(MIB_TABLE_ME65427_T)));
    OMCI_MeOperCfg(MIB_TABLE_ME65427_INDEX, NULL, &me65427, MIB_ADD,
                   omci_GetOltAccAttrSet(MIB_TABLE_ME65427_INDEX, OMCI_ME_ATTR_ACCESS_SBC), OMCI_MSG_BASELINE_PRI_LOW);
 
 
    return GOS_OK;
}

GOS_ERROR_CODE HwMe65427DrvCfg(void           *pOldRow,
                            void            *pNewRow,
                            MIB_OPERA_TYPE  operationType,
                            MIB_ATTRS_SET   attrSet,
                            UINT32          pri)
{
    return GOS_OK;
}


GOS_ERROR_CODE mibTable_init ( MIB_TABLE_INDEX tableId )
{
    UINT8 proprietary_mib_cb_bitmask = 0;
    UINT8 isIgnore = 0;

    if(GOS_OK == omci_ignore_mib_table_check(65427, OMCI_ME_CLASS_SUB_DEFAULT, &isIgnore))
    {
        if(isIgnore)
        {
	        OMCI_PRINT("Ignore classId:%d", 65427);
            return GOS_FAIL;
        }

    }


    MIB_TABLE_ME65427_INDEX = tableId;
    memset(&(gMibMe65427Oper), 0x0, sizeof(MIB_TABLE_OPER_T));

    gMibMe65427TableInfo.Name = "HW ME65427";
    gMibMe65427TableInfo.ShortName = "HW65427";
    gMibMe65427TableInfo.Desc = "huawei ME65427";
    gMibMe65427TableInfo.ClassId = (UINT32)(65427);
    gMibMe65427TableInfo.InitType = (UINT32)(OMCI_ME_INIT_TYPE_ONU);
    gMibMe65427TableInfo.StdType = (UINT32)(OMCI_ME_TYPE_PROPRIETARY);
    gMibMe65427TableInfo.ActionType = (UINT32)(OMCI_ME_ACTION_SET | OMCI_ME_ACTION_GET);
    gMibMe65427TableInfo.pAttributes = &(gMibMe65427AttrInfo[0]);
    gMibMe65427TableInfo.attrNum = MIB_TABLE_ME65427_ATTR_NUM;
    gMibMe65427TableInfo.entrySize = sizeof(MIB_TABLE_ME65427_T);
    gMibMe65427TableInfo.pDefaultRow = &gMibMe65427DefRow;

    gMibMe65427AttrInfo[MIB_TABLE_ME65427_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].Name = "EntityID";
    gMibMe65427AttrInfo[MIB_TABLE_ME65427_NO1_ATTR - MIB_TABLE_FIRST_INDEX].Name = "First";
    gMibMe65427AttrInfo[MIB_TABLE_ME65427_NO2_ATTR - MIB_TABLE_FIRST_INDEX].Name = "Second";

    gMibMe65427AttrInfo[MIB_TABLE_ME65427_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].Desc = "Entity ID";
    gMibMe65427AttrInfo[MIB_TABLE_ME65427_NO1_ATTR - MIB_TABLE_FIRST_INDEX].Desc = "First";
    gMibMe65427AttrInfo[MIB_TABLE_ME65427_NO2_ATTR - MIB_TABLE_FIRST_INDEX].Desc = "Second";

    gMibMe65427AttrInfo[MIB_TABLE_ME65427_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT16;
    gMibMe65427AttrInfo[MIB_TABLE_ME65427_NO1_ATTR - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_UINT16;
    gMibMe65427AttrInfo[MIB_TABLE_ME65427_NO2_ATTR - MIB_TABLE_FIRST_INDEX].DataType = MIB_ATTR_TYPE_STR;

    gMibMe65427AttrInfo[MIB_TABLE_ME65427_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].Len = 2;
    gMibMe65427AttrInfo[MIB_TABLE_ME65427_NO1_ATTR - MIB_TABLE_FIRST_INDEX].Len = 2;
    gMibMe65427AttrInfo[MIB_TABLE_ME65427_NO2_ATTR - MIB_TABLE_FIRST_INDEX].Len = 24;

    gMibMe65427AttrInfo[MIB_TABLE_ME65427_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].IsIndex = TRUE;
    gMibMe65427AttrInfo[MIB_TABLE_ME65427_NO1_ATTR - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;
    gMibMe65427AttrInfo[MIB_TABLE_ME65427_NO2_ATTR - MIB_TABLE_FIRST_INDEX].IsIndex = FALSE;

    gMibMe65427AttrInfo[MIB_TABLE_ME65427_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].MibSave = TRUE;
    gMibMe65427AttrInfo[MIB_TABLE_ME65427_NO1_ATTR - MIB_TABLE_FIRST_INDEX].MibSave = FALSE;
    gMibMe65427AttrInfo[MIB_TABLE_ME65427_NO2_ATTR - MIB_TABLE_FIRST_INDEX].MibSave = FALSE;

    gMibMe65427AttrInfo[MIB_TABLE_ME65427_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibMe65427AttrInfo[MIB_TABLE_ME65427_NO1_ATTR - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;
    gMibMe65427AttrInfo[MIB_TABLE_ME65427_NO2_ATTR - MIB_TABLE_FIRST_INDEX].OutStyle = MIB_ATTR_OUT_HEX;

    gMibMe65427AttrInfo[MIB_TABLE_ME65427_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ;
    gMibMe65427AttrInfo[MIB_TABLE_ME65427_NO1_ATTR - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;
    gMibMe65427AttrInfo[MIB_TABLE_ME65427_NO2_ATTR - MIB_TABLE_FIRST_INDEX].OltAcc = OMCI_ME_ATTR_ACCESS_READ | OMCI_ME_ATTR_ACCESS_WRITE;

    gMibMe65427AttrInfo[MIB_TABLE_ME65427_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibMe65427AttrInfo[MIB_TABLE_ME65427_NO1_ATTR - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;
    gMibMe65427AttrInfo[MIB_TABLE_ME65427_NO2_ATTR - MIB_TABLE_FIRST_INDEX].AvcFlag = FALSE;

    gMibMe65427AttrInfo[MIB_TABLE_ME65427_ENTITYID_INDEX - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibMe65427AttrInfo[MIB_TABLE_ME65427_NO1_ATTR - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;
    gMibMe65427AttrInfo[MIB_TABLE_ME65427_NO2_ATTR - MIB_TABLE_FIRST_INDEX].OptionType = OMCI_ME_ATTR_TYPE_MANDATORY;

    gMibMe65427Oper.meOperCb[PROPRIETARY_MIB_CB_RESET] = omci_mib_me_65427_oper_reset;
    gMibMe65427Oper.meOperDump = omci_mib_oper_dump_default_handler;
	gMibMe65427Oper.meOperDrvCfg = HwMe65427DrvCfg;
    proprietary_mib_cb_bitmask = (1 << PROPRIETARY_MIB_CB_RESET);


    MIB_InfoRegister(tableId, &gMibMe65427TableInfo, &gMibMe65427Oper);
    MIB_RegisterCallback(tableId, NULL, NULL);

    MIB_Proprietary_Reg(tableId, proprietary_mib_cb_bitmask);

    return GOS_OK;
}
